package com.fdb.efp.nls.service.common.rules.apply;

import com.fdb.basic.framework.core.constant.EsbRetCodeStandard;
import com.fdb.basic.framework.core.exception.BizException;
import com.fdb.basic.framework.core.util.DateUtility;
import com.fdb.efp.nls.service.common.rules.CheckRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 需求编号:2019D08--
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2019/12/4
 * 功能描述:
 * 修改日期:2019/12/4
 * 修改描述:
 */
public class CertEndDtRule implements CheckRule {
    private static Logger logger = LoggerFactory.getLogger(ValidateFormatDate.class);
    private String indivIdExpDt;
    private String applyDate;

    public CertEndDtRule(String indivIdExpDt,String applyDate) {
        this.indivIdExpDt = indivIdExpDt;
        this.applyDate = applyDate;
    }

    @Override
    public void check() throws BizException {
        if (indivIdExpDt == null || indivIdExpDt.equals("")) {
            logger.error("查询到用户的证件到期日为空!");
            throw new BizException(EsbRetCodeStandard.KHXXJYBTG.getValue(),"查询到用户的证件到期日为空!");
        }
        String expDt = indivIdExpDt;
        if (indivIdExpDt.contains("长期")){
            expDt = "2099-12-31";
        }else if (indivIdExpDt.length()>10){
            indivIdExpDt = indivIdExpDt.substring(indivIdExpDt.length()-8,indivIdExpDt.length());
            expDt = DateUtility.format8To10(indivIdExpDt);
        }
        if (DateUtility.compareToDate(expDt,applyDate) < 0) {
            logger.error("申请用户证件已到期");
            throw new BizException(EsbRetCodeStandard.KHXXJYBTG.getValue(),"申请用户证件已到期!");
        }
    }
}
